package com.jian.springbootdemosdk.utils;


import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;

import java.util.HashMap;
import java.util.Map;

public class JApiUtils {
    public static String sign(String body, String securityKey) {
        String sign = SecureUtil.sha256(body + securityKey);
        return sign;
    }

    public static Map<String, String> getHead(Object body, Long interfaceId, String accessKey, String securityKey) {
        Map<String, String> heads = new HashMap<>();
        heads.put("accessKey", accessKey);
//        heads.put("securityKey",securityKey);
        body = SecureUtil.md5(body.toString());
        heads.put("sign", JApiUtils.sign(body.toString(), securityKey));
        heads.put("rand", RandomUtil.randomString(16));
        heads.put("timestamp", System.currentTimeMillis() + "");
        heads.put("expiration", 5 * 60 * 1000 + "");
        heads.put("body", body.toString());
        heads.put("interfaceId", interfaceId + "");
        return heads;
    }
}
